package com.cloudschool.media.service;

import com.cloudschool.base.model.PageParams;
import com.cloudschool.base.model.PageResult;
import com.cloudschool.base.model.RestResponse;
import com.cloudschool.media.model.dto.QueryMediaParamsDto;
import com.cloudschool.media.model.dto.UploadFileParamsDto;
import com.cloudschool.media.model.dto.UploadFileResultDto;
import com.cloudschool.media.model.po.MediaFiles;

import java.io.File;

/**
 * @author Mr.M
 * @version 1.0
 * @description 媒资文件管理业务类
 * @date 2022/9/10 8:55
 */
public interface MediaFileService {

    /**
     * @param pageParams          分页参数
     * @param queryMediaParamsDto 查询条件
     * @return com.xuecheng.base.model.PageResult<com.xuecheng.media.model.po.MediaFiles>
     * @description 媒资文件查询方法
     * @author Mr.M
     * @date 2022/9/10 8:57
     */
    PageResult<MediaFiles> queryMediaFiels(Long companyId, PageParams pageParams, QueryMediaParamsDto queryMediaParamsDto);

    /**
     * @param companyId
     * @param uploadFileParamsDto 上传文件信息
     * @param bytes
     * @param folder              文件目录,如果不传则默认年、月、日
     * @param objectName
     * @return com.cloudschool.media.model.dto.UploadFileResultDto
     * @description 上传文件
     * @author chenhong
     * @date 2023/3/11 16:25
     */
    UploadFileResultDto uploadFile(Long companyId, UploadFileParamsDto uploadFileParamsDto, byte[] bytes, String folder, String objectName);

    MediaFiles addMediaFilesToDb(Long companyId, String fileMd5, UploadFileParamsDto uploadFileParamsDto, String bucket, String objectName);

    /**
     * @param fileMd5
     * @return com.cloudschool.base.model.RestResponse<java.lang.Boolean>
     * @description 检查文件是否存在
     * @author chenhong
     * @date 2023/3/12 15:40
     */
    RestResponse<Boolean> checkFile(String fileMd5);


    /**
     * @param fileMd5
     * @param chunkIndex
     * @return com.cloudschool.base.model.RestResponse<java.lang.Boolean>
     * @description 检查分块是否存在
     * @author chenhong
     * @date 2023/3/12 15:40
     */
    RestResponse<Boolean> checkChunk(String fileMd5, int chunkIndex);

    /**
     * @param fileMd5 文件md5
     * @param chunk   分块序号
     * @param bytes   文件字节
     * @return com.cloudschool.base.model.RestResponse
     * @description 上传分块
     * @author chenhong
     * @date 2023/3/12 15:49
     */
    RestResponse uploadChunk(String fileMd5, int chunk, String localChunkFilePath);


    /**
     * @param companyId           机构id
     * @param fileMd5             文件md5
     * @param chunkTotal          分块总和
     * @param uploadFileParamsDto 文件信息
     * @return com.cloudschool.base.model.RestResponse
     * @description 合并分块
     * @author chenhong
     * @date 2023/3/12 15:55
     */
    RestResponse mergechunks(Long companyId, String fileMd5, int chunkTotal, UploadFileParamsDto uploadFileParamsDto) throws Exception;

    //  RestResponse mergechunks2(Long companyId, String fileMd5, int chunkTotal, UploadFileParamsDto uploadFileParamsDto) throws Exception;

    File downloadFileFromMinIO(String bucket, String objectName);

    boolean addMediaFilesToMinIO(String localFilePath, String mimeType, String bucket, String objectName);

    MediaFiles getFileById(String mediaId);
}
